mod login_state;
mod tray;

#[tauri::command]
fn greet(name: &str) -> String {
    format!("Hello, {}! You've been greeted from Rust!", name)
}

/// 退出应用程序的命令
/// * `exit_code` - 退出代码，0表示可正常退出，这里写死前端就不用传参了
#[tauri::command]
fn app_exit() {
    // 使用标准库的exit函数退出应用程序
    // 这个函数不会返回，而是直接终止进程
    std::process::exit(0);
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_notification::init())
        .plugin(tauri_plugin_dialog::init())
        .plugin(tauri_plugin_opener::init())
        .invoke_handler(tauri::generate_handler![
            greet,
            login_state::set_login_status,
            login_state::get_login_status,
            tray::create_tray,
            tray::destroy_tray,
            app_exit
        ])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
